const sq = require("../../db/mysql");

module.exports = {
  async list(page = 1, count = 10, type = "update_at", order = "DESC") {
    try {
      let data = await sq.model("product").findAndCountAll({
        order: [[type, order]],
        limit: count,
        offset: (page-1) * count
      });
      return {code: 200, data: data.rows};
    } catch (error) {
        console.log(error);
        return {code: 400, msg: '查找出错'}
    }
  },
  async detail(id) {
      try {
          let data = await sq.model("product").findOne({where:{id: id}});
          return {code: 200, data: data.dataValues}
      } catch (error) {
          console.log(error);
          return {code: 400, msg: '查找出错'}
      }
  }
};
